package com.own.business.system.user.entity.vo;

import com.own.business.system.user.entity.po.SystemUserSecurity;
import com.own.component.common.base.entity.vo.BaseVo;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

/**
 * SystemUserSecurityVo
 *
 * @author chenxueli
 * @date 2021/06/25 16:51:09
 */
@Schema(title = "系统用户账号安全" + ConstantBeanSuffix.VO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class SystemUserSecurityVo extends BaseVo<SystemUserSecurity> {

    @Schema(title = "用户id")
    private Long userId;

    @Schema(title = "是否允许使用姓名登录 1=允许 0=不允许")
    private Integer allowLoginName;

    @Schema(title = "是否允许使用手机号登录 1=允许 0=不允许")
    private Integer allowLoginPhone;

    @Schema(title = "是否允许使用短信验证码登录 1=允许 0=不允许")
    private Integer allowLoginSms;

    @Schema(title = "是否允许使用密码登录 1=允许 0=不允许")
    private Integer allowLoginPassword;

    @Schema(title = "是否允许使用邮箱登录 1=允许 0=不允许")
    private Integer allowLoginEmail;

    @Schema(title = "是否开启登录的ip验证 1=需要 0=不需要")
    private Integer allowLoginIp;

    @Schema(title = "允许登录的ip，登录ip设置127.0.0.1为全网都能登录")
    private String loginIps;

    /**
     * 构造方法
     *
     * @param entity 原对象
     */
    public SystemUserSecurityVo(@NonNull SystemUserSecurity entity) {
        super(entity);
        this.userId = entity.getFkUserId();
        this.allowLoginName = entity.getAllowLoginName();
        this.allowLoginPhone = entity.getAllowLoginPhone();
        this.allowLoginSms = entity.getAllowLoginSms();
        this.allowLoginPassword = entity.getAllowLoginPassword();
        this.allowLoginEmail = entity.getAllowLoginEmail();
        this.allowLoginIp = entity.getAllowLoginIp();
        this.loginIps = entity.getLoginIps();
    }

    /**
     * 转po对象
     *
     * @param entity 原
     * @return po对象
     */
    @Override
    public SystemUserSecurity toPo(SystemUserSecurity entity) {
        if (entity == null) {
            entity = new SystemUserSecurity();
        }
        entity.setFkUserId(this.userId);
        entity.setAllowLoginName(this.allowLoginName);
        entity.setAllowLoginPhone(this.allowLoginPhone);
        entity.setAllowLoginSms(this.allowLoginSms);
        entity.setAllowLoginPassword(this.allowLoginPassword);
        entity.setAllowLoginEmail(this.allowLoginEmail);
        entity.setAllowLoginIp(this.allowLoginIp);
        entity.setLoginIps(this.loginIps);
        return super.toPo(entity);
    }

}
